﻿

app.controller('SafetyResponsibilityController', function ($scope, $http, $window, $compile, $filter, ipCookie, common, option, Upload) {
    $scope.result = {};
    $scope.dateOption = option.date;
    $scope.datetimeOption = option.datetime;

    $scope.BindDepartmentList = function (control, defaultvalue) {
        $scope.PageLoading = true;
        $http({
            method: 'POST',
            url: '../HiddenTrouble/GetDepartmentList'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $.each(ret.Data, function (i, n) {
                        if (n.DepartmentName != "系统支持") {
                            if (defaultvalue != null) {
                                if (n.Id == defaultvalue)
                                    $("#" + control).append($compile("<option selected='selected' value=\"" + n.Id + "\">" + n.DepartmentName + "</option>")($scope));
                                else
                                    $("#" + control).append($compile("<option value=\"" + n.Id + "\">" + n.DepartmentName + "</option>")($scope));
                            }
                            else {
                                $("#" + control).append($compile("<option value=\"" + n.Id + "\">" + n.DepartmentName + "</option>")($scope));
                            }
                        }
                    })
                    $("#" + control).selectpicker('refresh');
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetMyResponsibility = function () {
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/GetMyResponsibility'
        }).success(function (ret) {
            if (ret.Code == 100) {
                $scope.ResponsibilityDetail = ret.Data;
            } else
                alertify.alert(ret.Msg);
        }).error(function (data, status, headers, config) {
            common.error($scope);
            $scope.PageLoading = false;
            alertify.alert("请检查网络");
        })
    }

    $scope.GetJobPageList = function (model, page) {
        $scope.DataLoading = true;
        $scope.JobTitleList = [];
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/GetJobTitlePageList',
            data: { "model": model },
            params: { 'page': page }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.TotalCount = ret.Data.TotalItemCount;
                    $scope.JobTitleList = ret.Data.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetResponsibilityList = function (Id) {
        $scope.DataLoading = true;
        $scope.ResponsibilityList = [];
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/GetResponsibilityList',
            data: { "Id": Id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.TotalCount = ret.Data.length;
                    $scope.ResponsibilityList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetJobTitle = function (Id) {
        $scope.DataLoading = true;
        $scope.JobTitle = {};
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/GetJobTitle',
            data: { "Id": Id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.TotalCount = ret.Data.length;
                    $scope.JobTitle = ret.Data;
                    $scope.JobTitle.CreateTime = $filter('JSONDate')($scope.JobTitle.CreateTime, 'yyyy-MM-dd HH:mm:ss');
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.AddJobTitle = function (model, page) {
        if (model.JobTitle == null || model.JobTitle == "") {
            alertify.alert("请填写职位名称！");
            return false;
        }
        $scope.DataLoading = true;
        $scope.LoadingMsg = "正在提交,请稍后...";
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/AddJobTitle',
            data: { 'model': model }
        })
            .success(function (ret) {
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    alertify.alert(ret.Msg);
                    setTimeout(function () {
                        location.href = "JobTitlePageList?page=" + page;
                    }, 2000);
                } else
                    alertify.alert(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
                $scope.PageLoading = false;
                alertify.alert("请检查网络");

            })
    }

    $scope.AddJobResponsibility = function (model, page, jobtitle) {
        if (model.ContentText == null || model.ContentText == "") {
            alertify.alert("请填写职位名称！");
            return false;
        }
        $scope.DataLoading = true;
        $scope.LoadingMsg = "正在提交,请稍后...";
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/AddJobResponsibility',
            data: { 'model': model }
        })
            .success(function (ret) {
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    alertify.alert(ret.Msg);
                    setTimeout(function () {
                        location.href = "JobResponsibilityList?page=" + page + "&Id=" + model.JobTitleId + "&JobTitle=" + jobtitle;
                    }, 2000);
                } else
                    alertify.alert(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
                $scope.PageLoading = false;
                alertify.alert("请检查网络");

            })
    }

    $scope.EditJobTitle = function (model, page) {
        if (model.JobTitle == null || model.JobTitle == "") {
            alertify.alert("请填写职位名称！");
            return false;
        }
        $scope.DataLoading = true;
        $scope.LoadingMsg = "正在提交,请稍后...";
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/EditJobTitle',
            data: { 'model': model }
        })
            .success(function (ret) {
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    alertify.alert(ret.Msg);
                    setTimeout(function () {
                        location.href = "JobTitlePageList?page=" + page;
                    }, 2000);
                } else
                    alertify.alert(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
                $scope.PageLoading = false;
                alertify.alert("请检查网络");

            })
    }

    $scope.DeleteJobTitle = function (Id, SearchModel, page) {
        alertify.okBtn("确认")
            .cancelBtn("取消").confirm("确认此操作？", function (ev) {
                ev.preventDefault();
                $scope.DataLoading = true;
                $http({
                    method: 'POST',
                    url: '../SafetyResponsibility/DeleteJobTitle',
                    data: { 'Id': Id }
                })
                    .success(function (ret) {
                        common.success($scope, null, ret);
                        $scope.DataLoading = false;
                        if (ret.Code == 100) {
                            alertify.alert("删除成功！");
                            $scope.GetJobPageList(SearchModel, page);
                        }
                        else {
                            alertify.alert(ret.Msg);
                            $scope.GetJobPageList(SearchModel, page);
                        }
                    })
                    .error(function (data, status, headers, config) {
                        $scope.DataLoading = false;
                    });
            }, function (ev) {
                ev.preventDefault();
            });
    }

    $scope.DeleteResponsibility = function (Id1, Id2) {
        alertify.okBtn("确认")
            .cancelBtn("取消").confirm("确认此操作？", function (ev) {
                ev.preventDefault();
                $scope.DataLoading = true;
                $http({
                    method: 'POST',
                    url: '../SafetyResponsibility/DeleteJobResponsibility',
                    data: { 'Id': Id1 }
                })
                    .success(function (ret) {
                        common.success($scope, null, ret);
                        $scope.DataLoading = false;
                        if (ret.Code == 100) {
                            alertify.alert("删除成功！");
                            $scope.GetResponsibilityList(Id2);;
                        }
                        else {
                            alertify.alert(ret.Msg);
                            $scope.GetResponsibilityList(Id2);;
                        }
                    })
                    .error(function (data, status, headers, config) {
                        $scope.DataLoading = false;
                    });
            }, function (ev) {
                ev.preventDefault();
            });
    }

    $scope.GetJobResponsibility = function (Id) {
        $scope.DataLoading = true;
        $scope.JobResponsibility = {};
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/GetJobResponsibility',
            data: { "Id": Id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.TotalCount = ret.Data.length;
                    $scope.JobResponsibility = ret.Data;
                    $scope.JobResponsibility.CreateTime = $filter('JSONDate')($scope.JobResponsibility.CreateTime, 'yyyy-MM-dd HH:mm:ss');
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.EditJobResponsibility = function (model, page, jobTitleId, jobTitle) {
        if (model.ContentText == null || model.ContentText == "") {
            alertify.alert("请填职责内容！");
            return false;
        }
        $scope.DataLoading = true;
        $scope.LoadingMsg = "正在提交,请稍后...";
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/EditJobResponsibility',
            data: { 'model': model }
        })
            .success(function (ret) {
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    alertify.alert(ret.Msg);
                    setTimeout(function () {
                        location.href = "JobResponsibilityList?page=" + page + "&Id=" + jobTitleId + "&JobTitle=" + jobTitle;
                    }, 2000);
                } else
                    alertify.alert(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
                $scope.PageLoading = false;
                alertify.alert("请检查网络");

            })
    }

    $scope.GetUserList = function (searchmodel, JobTitleId) {
        $scope.DataLoading = true;
        $scope.LoadingMsg = "页面加载中";
        $scope.UserList = [];
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/GetUserList',
            data: { 'model': searchmodel, 'JobTitleId': JobTitleId }
        }).success(function (ret) {
            $scope.DataLoading = false;
            common.success($scope, null, ret);
            if (ret.Code == 100) {
                $scope.UserList = ret.Data;
            } else {
                alertify.alert(ret.Msg);
            }
        }).error(function (data, status, headers, config) {
            common.error($scope);
            $scope.DataLoading = false;
            alertify.alert("请检查网络");
        })
    }

    $scope.GetPlaceUserList = function (searchmodel, Id) {
        $scope.DataLoading = true;
        $scope.LoadingMsg = "页面加载中";
        $scope.UserList = [];
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/GetPlaceUserList',
            data: { 'model': searchmodel, 'LevelId': Id }
        }).success(function (ret) {
            $scope.DataLoading = false;
            common.success($scope, null, ret);
            if (ret.Code == 100) {
                $scope.UserList = ret.Data;
            } else {
                alertify.alert(ret.Msg);
            }
        }).error(function (data, status, headers, config) {
            common.error($scope);
            $scope.DataLoading = false;
            alertify.alert("请检查网络");
        })
    }

    $scope.GetSelectedUserList = function (JobTitleId) {
        $scope.SelectedUserList = [];
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/GetSelectedUser',
            data: { 'JobTitleId': JobTitleId }
        }).success(function (ret) {
            $scope.DataLoading = false;
            common.success($scope, null, ret);
            if (ret.Code == 100) {
                $scope.SelectedUserList = ret.Data;
            } else {
                alertify.alert(ret.Msg);
            }
        }).error(function (data, status, headers, config) {
            common.error($scope);
            $scope.DataLoading = false;
            alertify.alert("请检查网络");
        })
    }

    $scope.GetPlaceSelectedUserList = function (Id) {
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/GetPlaceSelectedUser',
            data: { 'LevelId': Id }
        }).success(function (ret) {
            $scope.DataLoading = false;
            common.success($scope, null, ret);
            if (ret.Code == 100) {
                $scope.SelectedUserList = ret.Data;
            } else {
                alertify.alert(ret.Msg);
            }
        }).error(function (data, status, headers, config) {
            common.error($scope);
            $scope.DataLoading = false;
            alertify.alert("请检查网络");
        })
    }

    $scope.SelectAll = function () {
        var controls = $("input[id^='checkuser_']");
        if ($("#SelectAll").prop('checked')) {

            for (var i = 0; i < controls.length; i++) {
                $(controls[i]).prop("checked", true);
            }
        }
        else {
            for (var i = 0; i < controls.length; i++) {
                $(controls[i]).prop("checked", false);
            }
        }
    }

    $scope.AddUserJobTitle = function (jobtitleid, userno, searchmodel) {
        $scope.DataLoading = true;
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/AddUserJobTitle',
            data: { 'UserNo': userno, 'JobTitleId': jobtitleid }
        }).success(function (ret) {
            $scope.DataLoading = false;
            common.success($scope, null, ret);
            if (ret.Code == 100) {
                $scope.GetUserList(searchmodel, jobtitleid);
                $scope.GetSelectedUserList(jobtitleid);

            } else {
                alertify.alert(ret.Msg);
            }
        }).error(function (data, status, headers, config) {
            $scope.DataLoading = false;
            common.error($scope);
            alertify.alert("请检查网络");
        })
    }

    $scope.AddUserPlace = function (Id, userno, searchmodel) {
        $scope.DataLoading = true;
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/AddUserPlace',
            data: { 'UserNo': userno, 'LevelId': Id }
        }).success(function (ret) {
            $scope.DataLoading = false;
            common.success($scope, null, ret);
            if (ret.Code == 100) {
                $scope.GetPlaceUserList(searchmodel, Id);
                $scope.GetPlaceSelectedUserList(Id);

            } else {
                alertify.alert(ret.Msg);
            }
        }).error(function (data, status, headers, config) {
            $scope.DataLoading = false;
            common.error($scope);
            alertify.alert("请检查网络");
        })
    }

    $scope.RemoveUserJobTitle = function (jobtitleid, userno, searchmodel) {
        $scope.DataLoading = true;
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/RemoveUserJobTitle',
            data: { 'UserNo': userno, 'JobTitleId': jobtitleid }
        }).success(function (ret) {
            $scope.DataLoading = false;
            common.success($scope, null, ret);
            if (ret.Code == 100) {
                $scope.GetUserList(searchmodel, jobtitleid);
                $scope.GetSelectedUserList(jobtitleid);
            } else {
                alertify.alert(ret.Msg);
            }
        }).error(function (data, status, headers, config) {
            $scope.DataLoading = false;
            common.error($scope);
            alertify.alert("请检查网络");
        })
    }

    $scope.RemoveUserPlace = function (Id, userno, searchmodel) {
        $scope.DataLoading = true;
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/RemoveUserPlace',
            data: { 'UserNo': userno, 'LevelId': Id }
        }).success(function (ret) {
            $scope.DataLoading = false;
            common.success($scope, null, ret);
            if (ret.Code == 100) {
                $scope.GetPlaceUserList(searchmodel, Id);
                $scope.GetPlaceSelectedUserList(Id);
            } else {
                alertify.alert(ret.Msg);
            }
        }).error(function (data, status, headers, config) {
            $scope.DataLoading = false;
            common.error($scope);
            alertify.alert("请检查网络");
        })
    }

    $scope.GetUserJobTitlePageList = function (searchmodel, page) {
        $scope.PageLoading = true;
        $scope.LoadingMsg = "页面加载中";
        $scope.UserList = [];
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/GetUserJobTitlePageList',
            data: { 'model': searchmodel },
            params: { 'page': page }
        }).success(function (ret) {
            $scope.PageLoading = false;
            common.success($scope, null, ret);
            if (ret.Code == 100) {
                $scope.UserList = ret.Data.Data;
            } else {
                alertify.alert(ret.Msg);
            }
        }).error(function (data, status, headers, config) {
            common.error($scope);
            $scope.DataLoading = false;
            alertify.alert("请检查网络");
        })
    }

    $scope.GetPlaceResponsibilityList = function (Id) {
        $scope.DataLoading = true;
        $scope.ResponsibilityList = [];
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/GetPlaceResponsibilityList',
            data: { "Id": Id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.TotalCount = ret.Data.length;
                    $scope.ResponsibilityList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetPlaceResponsibilityLevelList = function (Id) {
        $scope.DataLoading = true;
        $scope.LevelList = [];
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/GetPlaceResponsibilityLevelList',
            data: { "PlaceId": Id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.TotalCount = ret.Data.length;
                    $scope.LevelList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetPlaceMeasuresList = function (Id) {
        $scope.DataLoading = true;
        $scope.ResponsibilityList = [];
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/GetPlaceMeasuresList',
            data: { "Id": Id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.TotalCount = ret.Data.length;
                    $scope.ResponsibilityList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.AddPlaceResponsibility = function (model, page, placename) {
        if (model.ContentText == null || model.ContentText == "") {
            alertify.alert("请填写职责内容！");
            return false;
        }
        $scope.DataLoading = true;
        $scope.LoadingMsg = "正在提交,请稍后...";
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/AddPlaceResponsibility',
            data: { 'model': model }
        })
            .success(function (ret) {
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    alertify.alert(ret.Msg);
                    setTimeout(function () {
                        location.href = "PlaceResponsibilityList?page=" + page + "&Id=" + model.PlaceId + "&PlaceName=" + placename;
                    }, 2000);
                } else
                    alertify.alert(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
                $scope.PageLoading = false;
                alertify.alert("请检查网络");

            })
    }

    $scope.AddPlaceMeasures = function (model, page, placename, pagename, placeId) {
        if (model.ContentText == null || model.ContentText == "") {
            alertify.alert("请填写措施内容！");
            return false;
        }
        var ulist = $("#User_Select").val();
        if (ulist == null || ulist.length == 0) {
            alertify.alert("请选择责任人！");
            return false;
        }
        $scope.DataLoading = true;
        $scope.LoadingMsg = "正在提交,请稍后...";
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/AddPlaceMeasures',
            data: { 'model': model, "UserNos": ulist }
        })
            .success(function (ret) {
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    alertify.alert(ret.Msg);
                    setTimeout(function () {
                        location.href = "PlaceRiskList?page=" + page + "&RiskId=" + model.RiskId + "&PlaceName=" + placename + "&PlaceId=" + placeId;
                    }, 2000);
                } else
                    alertify.alert(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
                $scope.PageLoading = false;
                alertify.alert("请检查网络");

            })
    }

    $scope.DeletePlaceResponsibilityLevel = function (Id1, Id2) {
        alertify.okBtn("确认")
            .cancelBtn("取消").confirm("确认此操作？", function (ev) {
                ev.preventDefault();
                $scope.DataLoading = true;
                $http({
                    method: 'POST',
                    url: '../SafetyResponsibility/DeletePlaceResponsibilityLevel',
                    data: { 'Id': Id1 }
                })
                    .success(function (ret) {
                        common.success($scope, null, ret);
                        $scope.DataLoading = false;
                        if (ret.Code == 100) {
                            alertify.alert("删除成功！");
                            $scope.GetPlaceResponsibilityList(Id2);;
                        }
                        else {
                            alertify.alert(ret.Msg);
                            $scope.GetPlaceResponsibilityList(Id2);;
                        }
                    })
                    .error(function (data, status, headers, config) {
                        $scope.DataLoading = false;
                    });
            }, function (ev) {
                ev.preventDefault();
            });
    }

    $scope.DeletePlaceMeasures = function (Id1, Id2) {
        alertify.okBtn("确认")
            .cancelBtn("取消").confirm("确认此操作？", function (ev) {
                ev.preventDefault();
                $scope.DataLoading = true;
                $http({
                    method: 'POST',
                    url: '../SafetyResponsibility/DeletePlaceMeasures',
                    data: { 'Id': Id1 }
                })
                    .success(function (ret) {
                        common.success($scope, null, ret);
                        $scope.DataLoading = false;
                        if (ret.Code == 100) {
                            alertify.alert("删除成功！");
                            $scope.GetRiskList(Id2);
                        }
                        else {
                            alertify.alert(ret.Msg);
                            $scope.GetRiskList(Id2);
                        }
                    })
                    .error(function (data, status, headers, config) {
                        $scope.DataLoading = false;
                    });
            }, function (ev) {
                ev.preventDefault();
            });
    }

    $scope.GetPlaceResponsibility = function (Id) {
        $scope.DataLoading = true;
        $scope.JobResponsibility = {};
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/GetPlaceResponsibility',
            data: { "Id": Id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.PlaceResponsibility = ret.Data;
                    $scope.PlaceResponsibility.CreateTime = $filter('JSONDate')($scope.JobResponsibility.CreateTime, 'yyyy-MM-dd HH:mm:ss');
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetPlaceMeasures = function (Id) {
        $scope.DataLoading = true;
        $scope.JobResponsibility = {};
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/GetPlaceMeasures',
            data: { "Id": Id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.PlaceResponsibility = ret.Data;
                    $scope.PlaceResponsibility.CreateTime = $filter('JSONDate')($scope.PlaceResponsibility.CreateTime, 'yyyy-MM-dd HH:mm:ss');
                    $scope.BindEmployeeList('User_Select', $scope.PlaceResponsibility.UserNo);
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.EditPlaceResponsibility = function (model, page, placeId, placename) {
        if (model.ContentText == null || model.ContentText == "") {
            alertify.alert("请填职责内容！");
            return false;
        }

        $scope.DataLoading = true;
        $scope.LoadingMsg = "正在提交,请稍后...";
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/EditPlaceResponsibility',
            data: { 'model': model }
        })
            .success(function (ret) {
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    alertify.alert(ret.Msg);
                    setTimeout(function () {
                        location.href = "PlaceResponsibilityList?page=" + page + "&Id=" + placeId + "&PlaceName=" + placename;
                    }, 2000);
                } else
                    alertify.alert(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
                $scope.PageLoading = false;
                alertify.alert("请检查网络");

            })
    }

    $scope.EditPlaceMeasures = function (model, page, placeId, placename) {
        if (model.ContentText == null || model.ContentText == "") {
            alertify.alert("请填场所措施内容！");
            return false;
        }
        var ulist = $("#User_Select").val();
        if (ulist == null || ulist.length == 0) {
            alertify.alert("请选择责任人！");
            return false;
        }
        $scope.DataLoading = true;
        $scope.LoadingMsg = "正在提交,请稍后...";
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/EditPlaceMeasures',
            data: { 'model': model, "UserNos": ulist }
        })
            .success(function (ret) {
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    alertify.alert(ret.Msg);
                    setTimeout(function () {
                        location.href = "PlaceRiskList?page=" + page + "&PlaceId=" + placeId + "&PlaceName=" + placename;
                    }, 2000);
                } else
                    alertify.alert(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
                $scope.PageLoading = false;
                alertify.alert("请检查网络");

            })
    }

    $scope.AddPlaceResponsibilityLevel = function (model, page, placename) {
        if (model.LevelName == null || model.LevelName == "") {
            alertify.alert("请填写层级！");
            return false;
        }
        if (model.Interval == null || model.Interval == "") {
            alertify.alert("请填写检查频次！");
            return false;
        }
        $scope.DataLoading = true;
        $scope.LoadingMsg = "正在提交,请稍后...";
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/AddPlaceResponsibilityLevel',
            data: { 'model': model }
        })
            .success(function (ret) {
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    alertify.alert(ret.Msg);
                    setTimeout(function () {
                        location.href = "PlaceResponsibilityLevelList?page=" + page + "&Id=" + model.PlaceId + "&PlaceName=" + placename;
                    }, 2000);
                } else
                    alertify.alert(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
                $scope.PageLoading = false;
                alertify.alert("请检查网络");

            })
    }

    $scope.GetSingleResponsibilityLevel = function (model) {
        var tempmodel = JSON.parse(JSON.stringify(model));
        $scope.EditModel = tempmodel;
        $scope.EditModel.Interval = $scope.EditModel.Interval + '';
        $scope.EditModel.CreateTime = $filter('JSONDate')($scope.EditModel.CreateTime, 'yyyy-MM-dd HH:mm:ss');
    }

    $scope.EditPlaceResponsibilityLevel = function (model) {
        if (model.LevelName == null || model.LevelName == "") {
            alertify.alert("请填写层级！");
            return false;
        }
        if (model.Interval == null || model.Interval == "") {
            alertify.alert("请填写检查频次！");
            return false;
        }
        $scope.DataLoading = true;
        $scope.LoadingMsg = "正在提交,请稍后...";
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/EditPlaceResponsibilityLevel',
            data: { 'model': model }
        })
            .success(function (ret) {
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    alertify.alert(ret.Msg);
                    setTimeout(function () {
                        $("#close1").click();
                        $scope.GetPlaceResponsibilityLevelList($scope.Id);
                    }, 2000);
                } else
                    alertify.alert(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
                $scope.PageLoading = false;
                alertify.alert("请检查网络");

            })
    }

    $scope.AddPlaceRisk = function (model, page, placename) {
        if (model.RiskContent == null || model.RiskContent == "") {
            alertify.alert("请填写措施内容！");
            return false;
        }
        $scope.DataLoading = true;
        $scope.LoadingMsg = "正在提交,请稍后...";
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/AddPlaceRisk',
            data: { 'model': model }
        })
            .success(function (ret) {
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    alertify.alert(ret.Msg);
                    setTimeout(function () {
                        location.href = "PlaceRiskList?page=" + page + "&PlaceId=" + model.PlaceId + "&PlaceName=" + placename;
                    }, 2000);
                } else
                    alertify.alert(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
                $scope.PageLoading = false;
                alertify.alert("请检查网络");

            })
    }

    $scope.GetRiskTypeList = function () {
        $scope.DataLoading = true;
        $scope.RiskTypeList = [];
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/GetRiskTypeList'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.RiskTypeList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetRiskLevelList = function () {
        $scope.DataLoading = true;
        $scope.RiskLevelList = [];
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/GetRiskLevelList'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.RiskLevelList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetRiskList = function (Id) {
        $scope.DataLoading = true;
        $scope.RiskList = [];
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/GetRiskList',
            data: { 'PlaceId': Id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.RiskList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.BindEmployeeList = function (control, defaultvalue) {
        $scope.PageLoading = true;
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/GetEmployeeList'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $.each(ret.Data, function (i, n) {
                        if (n.EmployeeNo == null || n.EmployeeNo === "") {

                        }
                        else {
                            if (defaultvalue != null) {
                                if (defaultvalue.includes(n.EmployeeNo))
                                    $("#" + control).append($compile("<option selected='selected' value=\"" + n.EmployeeNo + "\">" + n.EmployeeNo + "-" + n.EmployeeName + "</option>")($scope));
                                else
                                    $("#" + control).append($compile("<option value=\"" + n.EmployeeNo + "\">" + n.EmployeeNo + "-" + n.EmployeeName + "</option>")($scope));
                            }
                            else {
                                $("#" + control).append($compile("<option value=\"" + n.EmployeeNo + "\">" + n.EmployeeNo + "-" + n.EmployeeName + "</option>")($scope));
                            }
                        }

                    })
                    $("#" + control).selectpicker('refresh');
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.DeletePlaceRisk = function (Id1, Id2) {
        alertify.okBtn("确认")
            .cancelBtn("取消").confirm("确认此操作？", function (ev) {
                ev.preventDefault();
                $scope.DataLoading = true;
                $http({
                    method: 'POST',
                    url: '../SafetyResponsibility/DeleteRisk',
                    data: { 'Id': Id1 }
                })
                    .success(function (ret) {
                        common.success($scope, null, ret);
                        $scope.DataLoading = false;
                        if (ret.Code == 100) {
                            alertify.alert("删除成功！");
                            $scope.GetRiskList(Id2);
                        }
                        else {
                            alertify.alert(ret.Msg);
                            $scope.GetRiskList(Id2);
                        }
                    })
                    .error(function (data, status, headers, config) {
                        $scope.DataLoading = false;
                    });
            }, function (ev) {
                ev.preventDefault();
            });
    }

    $scope.GetPlaceRisk = function (Id) {
        $scope.DataLoading = true;
        $scope.RiskModel = {};
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/GetPlaceRisk',
            data: { "Id": Id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.RiskModel = ret.Data;
                    $scope.RiskModel.CreateTime = $filter('JSONDate')($scope.RiskModel.CreateTime, 'yyyy-MM-dd HH:mm:ss');
                    $scope.RiskModel.TypeId = $scope.RiskModel.TypeId + "";
                    $scope.RiskModel.LevelId = $scope.RiskModel.LevelId + "";
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.EditPlaceRisk = function (model, page, placename) {
        if (model.RiskContent == null || model.RiskContent == "") {
            alertify.alert("请填写措施内容！");
            return false;
        }

        $scope.DataLoading = true;
        $scope.LoadingMsg = "正在提交,请稍后...";
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/EditPlaceRisk',
            data: { 'model': model }
        })
            .success(function (ret) {
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    alertify.alert(ret.Msg);
                    setTimeout(function () {
                        location.href = "PlaceRiskList?page=" + page + "&PlaceId=" + model.PlaceId + "&PlaceName=" + placename;
                    }, 2000);
                } else
                    alertify.alert(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
                $scope.PageLoading = false;
                alertify.alert("请检查网络");

            })
    }

    $scope.AddPlaceResponsibilityAttr = function (model, page, placename, pagename, placeId) {
        if (model.ResponsibilityName == null || model.ResponsibilityName == "") {
            alertify.alert("请填写属性名称！");
            return false;
        }
        var ulist = $("#User_Select").val();

        var dlist = $("#Dep_Select").val();

        $scope.DataLoading = true;
        $scope.LoadingMsg = "正在提交,请稍后...";
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/AddResponsibilityAttr',
            data: { 'model': model, "UserNos": ulist, "DepartmentList": dlist }
        })
            .success(function (ret) {
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    alertify.alert(ret.Msg);
                    setTimeout(function () {
                        location.href = "PlaceResponsibilityAttrList?page=" + page + "&PlaceId=" + model.PlaceId + "&PlaceName=" + placename;
                    }, 2000);
                } else
                    alertify.alert(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
                $scope.PageLoading = false;
                alertify.alert("请检查网络");

            })
    }

    $scope.GetPlaceResponsibilityAttrList = function (Id) {
        $scope.DataLoading = true;
        $scope.AttrList = [];
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/GetResponsibilityAttrList',
            data: { 'PlaceId': Id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.AttrList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.DeleteResponsibilityAttr = function (Id1, Id2) {
        alertify.okBtn("确认")
            .cancelBtn("取消").confirm("确认此操作？", function (ev) {
                ev.preventDefault();
                $scope.DataLoading = true;
                $http({
                    method: 'POST',
                    url: '../SafetyResponsibility/DeleteResponsibilityAttr',
                    data: { 'Id': Id1 }
                })
                    .success(function (ret) {
                        common.success($scope, null, ret);
                        $scope.DataLoading = false;
                        if (ret.Code == 100) {
                            alertify.alert("删除成功！");
                            $scope.GetPlaceResponsibilityAttrList(Id2);
                        }
                        else {
                            alertify.alert(ret.Msg);
                            $scope.GetPlaceResponsibilityAttrList(Id2);
                        }
                    })
                    .error(function (data, status, headers, config) {
                        $scope.DataLoading = false;
                    });
            }, function (ev) {
                ev.preventDefault();
            });
    }

    $scope.GeteResponsibilityAttr = function (Id) {
        $scope.DataLoading = true;
        $scope.AttrModel = {};
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/GetResponsibilityAttr',
            data: { "Id": Id }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.AttrModel = ret.Data;
                    $scope.AttrModel.CreateTime = $filter('JSONDate')($scope.AttrModel.CreateTime, 'yyyy-MM-dd HH:mm:ss');
                    if ($scope.AttrModel.UserNo != null && $scope.AttrModel.UserNo) {
                        $scope.BindEmployeeList('User_Select', $scope.AttrModel.UserNo);
                    }
                    if ($scope.AttrModel.DepartmentList != null) {
                        $scope.BindDepartmentList2('Dep_Select', $scope.AttrModel.DepartmentList);
                    }
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.EditResponsibilityAttr = function (model, page, placename) {
        if (model.ResponsibilityName == null || model.ResponsibilityName == "") {
            alertify.alert("请填写属性名称！");
            return false;
        }
        var ulist = $("#User_Select").val();

        var dlist = $("#Dep_Select").val();

        $scope.DataLoading = true;
        $scope.LoadingMsg = "正在提交,请稍后...";
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/EditResponsibilityAttr',
            data: { 'model': model, "UserNos": ulist, "DepartmentList": dlist }
        })
            .success(function (ret) {
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    alertify.alert(ret.Msg);
                    setTimeout(function () {
                        location.href = "PlaceResponsibilityAttrList?page=" + page + "&PlaceId=" + model.PlaceId + "&PlaceName=" + placename;
                    }, 2000);
                } else
                    alertify.alert(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
                $scope.PageLoading = false;
                alertify.alert("请检查网络");

            })
    }

    $scope.BindDepartmentList2 = function (control, defaultvalue) {
        $scope.PageLoading = true;
        $http({
            method: 'POST',
            url: '../HiddenTrouble/GetDepartmentList'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $.each(ret.Data, function (i, n) {
                        if (n.DepartmentName != "系统支持") {
                            if (defaultvalue != null) {
                                if (defaultvalue.indexOf(""+n.Id)>-1)
                                    $("#" + control).append($compile("<option selected='selected' value=\"" + n.Id + "\">" + n.DepartmentName + "</option>")($scope));
                                else
                                    $("#" + control).append($compile("<option value=\"" + n.Id + "\">" + n.DepartmentName + "</option>")($scope));
                            }
                            else {
                                $("#" + control).append($compile("<option value=\"" + n.Id + "\">" + n.DepartmentName + "</option>")($scope));
                            }
                        }
                    })
                    $("#" + control).selectpicker('refresh');
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetCheckInterval = function () {
        $scope.IntervalList = [];
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/GetCheckInterval'
        })
            .success(function (ret) {
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.IntervalList = ret.Data;
                } else
                    alertify.alert(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
                $scope.PageLoading = false;
                alertify.alert("请检查网络");
            })
    }

    $scope.GetCheckItems = function (id,type) {
        $scope.CheckItemsList = [];
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/GetPlaceCheckItemList',
            data: { 'RoomId': id, 'CheckType': type }
        })
            .success(function (ret) {
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.CheckItemsList = ret.Data;
                } else
                    alertify.alert(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
                $scope.PageLoading = false;
                alertify.alert("请检查网络");
            })
    }

    $scope.UpdateCheckItems = function (id, type) {
        if (type == null) {
            alertify.alert("请选择检查频次");
            return false;
        }
        var idlist = [];
        var controllist = $("#SelectedCheckList li");
        for (var i = 0; i < controllist.length; i++) {
            var obj = {
                'RoomId': id,
                'TypeId': type,
                'OptionId': controllist[i].id,
                'SortBy':i
            };
            idlist.push(obj);
        }
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/UpdatePlaceCheckItem',
            data: { 'RoomId': id, 'CheckType': type, 'ItemList': idlist }
        })
            .success(function (ret) {
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    alertify.alert(ret.Msg);
                    $scope.GetCheckItems(id, type);
                } else
                    alertify.alert(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
                $scope.DataLoading = false;
                alertify.alert("请检查网络");
            })
    }

    $scope.SearchCheckOptions = function (content) {
        $scope.OptionList = [];
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/SearchCheckOptions',
            data: { 'CheckContent': content, 'Olist': $scope.CheckItemsList }
        })
            .success(function (ret) {
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.OptionList = ret.Data;
                } else
                    alertify.alert(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
                $scope.PageLoading = false;
                alertify.alert("请检查网络");
            })
    }

    $scope.RemoveCheckOption = function (list, x) {
        for (var i = 0; i < list.length; i++) {
            if (list[i].Id == x.Id) {
                list.splice(i, 1);
            }
        }
    }

    $scope.SelectCheckOption = function (list, model) {
        var obj = {
            'OptionId': model.Id,
            'CheckContent': model.CheckContent,
            'IsValue': model.IsValue
        };
        list.push(obj);
    }


    $scope.AddCheckOption = function (model) {
        if (model.CheckContent == null || model.CheckContent == "") {
            alertify.alert("请填写检查内容");
            return false;
        }     
        $http({
            method: 'POST',
            url: '../SafetyResponsibility/AddCheckOption',
            data: { 'model': model }
        })
            .success(function (ret) {
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.AlertBox("添加成功！");
                    model.CheckContent = "";
                    $("#close2").click();
                } else
                    alertify.alert(ret.Msg);
            })
            .error(function (data, status, headers, config) {
                common.error($scope);
                $scope.DataLoading = false;
                alertify.alert("请检查网络");
            })
    }

    $scope.ShowJobTitle = function (title) {
        $scope.JobTitle = title;
    }
});